﻿@using Aspire.Dashboard.Model
@using Aspire.Dashboard.Resources
@using System.Collections.Immutable
@using Aspire.Dashboard.Utils
@inject IStringLocalizer<ControlsStrings> Loc

<div class="structured-log-details-layout">
    <FluentToolbar Orientation="Orientation.Horizontal">
        <div>
            @((MarkupString)string.Format(ControlsStrings.StructuredLogsDetailsResource, ViewModel.LogEntry.ApplicationView.Application.ApplicationName))
        </div>
        <FluentDivider Role="DividerRole.Presentation" Orientation="Orientation.Vertical" />
        <div title="@FormatHelpers.FormatTimeWithOptionalDate(TimeProvider, ViewModel.LogEntry.TimeStamp, MillisecondsDisplay.Full)">
            @((MarkupString)string.Format(ControlsStrings.StructuredLogsDetailsTimestamp, FormatHelpers.FormatTimeWithOptionalDate(TimeProvider, ViewModel.LogEntry.TimeStamp, MillisecondsDisplay.Truncated)))
        </div>
        <FluentSearch Placeholder="@Loc[nameof(ControlsStrings.FilterPlaceholder)]"
                      Immediate="true"
                      Autofocus="true"
                      @bind-Value="_filter"
                      slot="end" />
    </FluentToolbar>
    <div class="property-grid-container">
        <FluentAccordion>
            <FluentAccordionItem Heading="@Loc[nameof(ControlsStrings.StructuredLogsDetailsLogEntryHeader)]" Expanded="true">
                <div slot="end">
                    <FluentBadge Appearance="Appearance.Neutral" Circular="true">
                        @FilteredItems.Count()
                    </FluentBadge>
                </div>
                <PropertyGrid TItem="TelemetryPropertyViewModel"
                              Items="@FilteredItems"
                              GridTemplateColumns="1fr 2fr"
                              HighlightText="@_filter" />
            </FluentAccordionItem>
            <FluentAccordionItem Heading="@Loc[nameof(ControlsStrings.StructuredLogsDetailsContextHeader)]" Expanded="true">
                <div slot="end">
                    <FluentBadge Appearance="Appearance.Neutral" Circular="true">
                        @FilteredContextItems.Count()
                    </FluentBadge>
                </div>
                <PropertyGrid TItem="TelemetryPropertyViewModel"
                              Items="@FilteredContextItems"
                              GridTemplateColumns="1fr 2fr"
                              HighlightText="@_filter" />
            </FluentAccordionItem>
            @if (_exceptionAttributes.Count > 0)
            {
                <FluentAccordionItem Heading="@Loc[nameof(ControlsStrings.StructuredLogsDetailsExceptionHeader)]" Expanded="true">
                    <div slot="end">
                        <FluentBadge Appearance="Appearance.Neutral" Circular="true">
                            @FilteredExceptionItems.Count()
                        </FluentBadge>
                    </div>
                    <PropertyGrid TItem="TelemetryPropertyViewModel"
                                  Items="@FilteredExceptionItems"
                                  GridTemplateColumns="1fr 2fr"
                                  HighlightText="@_filter" />
                </FluentAccordionItem>
            }
            <FluentAccordionItem Heading="@Loc[nameof(ControlsStrings.StructuredLogsDetailsResourceHeader)]" Expanded="true">
                <div slot="end">
                    <FluentBadge Appearance="Appearance.Neutral" Circular="true">
                        @FilteredResourceItems.Count()
                    </FluentBadge>
                </div>
                <PropertyGrid TItem="TelemetryPropertyViewModel"
                              Items="@FilteredResourceItems"
                              GridTemplateColumns="1fr 2fr"
                              HighlightText="@_filter" />
            </FluentAccordionItem>
        </FluentAccordion>
    </div>
</div>
